<?php

namespace app\constants;

class Acl
{
    //后台权限菜单
    public static $aclConfig = [
        
        '管理员模块' => [
            'url'    => '',
            'acl'    => 'admin',
            'action' => [
                [
                    'name'     => '用户管理',
                    'url'      => '/admin/admin/index',
                    'acl'      => 'admin_index',
                    'list_acl' => [
                        '添加' => 'admin_create',
                        '更新' => 'admin_update',
                        '删除' => 'admin_delete',
                    ],
                ],
                [
                    'name'     => '用户组&权限管理',
                    'url'      => '/admin/group/index',
                    'acl'      => 'group_index',
                    'list_acl' => [
                        '添加' => 'group_create',
                        '更新' => 'group_update',
                        '删除' => 'group_delete',
                    ],
                ],
                
            ],
        ],
        '文章管理' => [
            'url'    => '',
            'acl'    => 'article',
            'action' => [
                [
                    'name'     => '文章管理',
                    'url'      => '/admin/article/index',
                    'acl'      => 'article_index',
                    'list_acl' => [
                        '添加' => 'article_create',
                        '编辑' => 'article_edit',
                        '删除' => 'article_delete',
                    ],
                ],
            ],
        ],
        '工具管理' => [
            'url'    => '',
            'acl'    => 'tool',
            'action' => [
                [
                    'name'     => 'GM管理',
                    'url'      => '/admin/tool/gm',
                    'acl'      => 'tool_gm',
                    'list_acl' => [
                        'GM工具' => 'tool_gm',
                    ],
                ],
            ],
        ],
    ];

    /**
     * 用来判断第一级菜单是否高亮
     * @author chenym
     * @since  2017.7.6
     * @param $actions
     * @param string $localUrl
     * @return bool
     */
    public static function isActive($actions, $localUrl = '')
    {
        if (!$actions) {
            return false;
        }
        foreach ($actions as $k => $r) {
            if ($localUrl && $localUrl == $r['acl']) {
                return true;
            } else {
                false;
            }
        }
        return false;
    }
}
